//
//  LZFinancialDetailViewController.m
//  laziz_Merchant
//
//  Created by xbnzd on 16/12/17.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZFinancialDetailViewController.h"
#import "Masonry.h"
#import "UINavigationBar+BackgroundColor.h"
#import "UIViewController+NavigationItemSetting.h"
#import "UIView+Rotation.h"
#import "LZFinancialPresenter.h"
#import "LZFinancialSettlementAccountModel.h"
#import "LZDateFormatterManager.h"

@interface LZFinancialDetailViewController ()
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIButton *nav_left_back;
@property (nonatomic, strong) LZFinancialPresenter *financialPresenter;
@property (nonatomic, strong) LZFinancialSettlementAccountModel *accountModel;

@end

@implementation LZFinancialDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.umLogPageViewName = @"结款详情页面";
    self.title = LZLocalizedString(@"provision_details", nil);
    _financialPresenter = [[LZFinancialPresenter alloc] init];
    
    [self getData];
}



#pragma mark -
#pragma mark method
- (void)getData
{
    WS(wSelf);
   [self.financialPresenter getFinanicalSettlementAccountInfoWithID:self.payID ResultSuccess:^(LZFinancialSettlementAccountModel *dataModel) {
       wSelf.accountModel = dataModel;
       [wSelf configureContentUI];
       
   } Failure:^(NSString *fail) {
       
   }];
}


#pragma mark -
#pragma mark UI
- (void)configureContentUI
{
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    [self.view addSubview:_scrollView];
    
    UIView *bgView = [[UIView alloc] init];
    bgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [_scrollView addSubview:bgView];
    
    
    NSArray *titleArr = @[];
    if (self.accountModel.payMethod == 1) { //线上支付
        titleArr = @[LZLocalizedString(@"payment_serial_number", nil),
                     LZLocalizedString(@"provision_amount", nil),
                     LZLocalizedString(@"recipient's_online_account", nil),
                     LZLocalizedString(@"sender's_online_account", nil),
                     LZLocalizedString(@"provision_time_space", nil),
                     LZLocalizedString(@"remarks", nil)
                     ];
    }else if(self.accountModel.payMethod == 2){//线下支付
        titleArr = @[LZLocalizedString(@"payment_serial_number", nil),
                     LZLocalizedString(@"provision_amount", nil),
                     LZLocalizedString(@"recipient's_bank", nil),
                     LZLocalizedString(@"recipient's_full_name", nil),
                     LZLocalizedString(@"recipient's_bank_account", nil),
                     LZLocalizedString(@"provider's_bank", nil),
                     LZLocalizedString(@"sender's_name", nil),
                     LZLocalizedString(@"sender's_bank_account", nil),
                     LZLocalizedString(@"provision_time_space", nil),
                     LZLocalizedString(@"remarks", nil)
                     ];
    }
    
    
   
    CGFloat leftSpace = 15.0;
    CGFloat vSpace = 18.0;
    CGFloat hSpace = 10.0;
    
    
    for (int i = 0; i < titleArr.count; i ++) {
        UILabel *titleLabel = [self creatTitleLable];
        titleLabel.tag = i + 200;
        titleLabel.text = titleArr[i];
        
        UILabel *contentLabel = [self creatContentLable];
        contentLabel.tag = i + 100;
        contentLabel.text = [self returnTheContentText:i];
        
        [bgView addSubview:titleLabel];
        [bgView addSubview:contentLabel];
        
        //获取上一个内容label的底部位置
        UILabel *labelTemp = [bgView viewWithTag:i + 99];
        if (labelTemp.text.length == 0) {
            labelTemp = [bgView viewWithTag:i + 199];
        }
        //获取title的宽度
        CGFloat titleW = [self returnTitleWidth:titleLabel];
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            if (i == 0) {
                make.top.mas_equalTo(leftSpace);
            }else{
                make.top.equalTo(labelTemp.mas_bottom).offset(vSpace);
            }
            
            if (i == titleArr.count - 1) {
                make.bottom.lessThanOrEqualTo(leftSpace);
            }
            make.width.mas_equalTo(titleW);
            make.leading.mas_equalTo(leftSpace);
            
        }];

        [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel);
            make.leading.equalTo(titleLabel.mas_trailing).offset(hSpace);
            make.trailing.mas_equalTo(-leftSpace);
            
        }];
        
    }

    [bgView layoutIfNeeded];
    UILabel *l = [bgView viewWithTag:titleArr.count + 199];
    bgView.frame = CGRectMake(0, 0, SCREEN_WIDTH, l.frame.origin.y);
    _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, bgView.frame.size.height + 360);
}

- (NSString *)returnTheContentText:(NSInteger)index
{
    if (self.accountModel.payMethod == 1) {//线上支付
        switch (index) {
            case 0:
                return self.accountModel.payNumber;
                break;
                
            case 1:
                return [NSString stringWithFormat:@"%.3fBHD",self.accountModel.payMoney];
                break;
                
            case 2:
                return self.accountModel.receiptOnlineAccount;
                break;

            case 3:
                return self.accountModel.payOnlineAccount;
                break;
                
            case 4:
                return [[LZDateFormatterManager shareInstance] stringFromStringYMDHMSHaveLineyyyyMMddHHmmss:self.accountModel.payTime];
                break;
                
            case 5:
                return self.accountModel.remark;
                break;
                
            default:
                break;
        }

    }else if (self.accountModel.payMethod == 2){//线下支付
        switch (index) {
            case 0:
                return self.accountModel.payNumber;
                break;
                
            case 1:
                return [NSString stringWithFormat:@"%.3fBHD",self.accountModel.payMoney];
                break;
                
            case 2:
                return self.accountModel.receiptBankName;
                break;
                
            case 3:
                return self.accountModel.receiptUserFullName;
                break;
                
            case 4:
                return self.accountModel.receiptBankAccount;
                break;
                
            case 5:
                return self.accountModel.payBankName;
                break;
                
            case 6:
                return self.accountModel.payUserFullName;
                break;
                
            case 7:
                return self.accountModel.payBankAccount;
                break;
                
            case 8:
                return [[LZDateFormatterManager shareInstance] stringFromStringYMDHMSHaveLineyyyyMMddHHmmss:self.accountModel.payTime];
                break;
                
            case 9:
                return self.accountModel.remark;
                break;
                
            default:
                break;
        }

    }
    
    return @"";
}

- (UILabel *)creatContentLable
{ 
    UILabel *l = [[UILabel alloc] init];
    l.textColor = UIColorFromRGB(0x666666, 1);
    l.font = [UIFont systemFontOfSize:14];
    l.lineBreakMode = NSLineBreakByWordWrapping;
    l.numberOfLines = 0;
    
    return l;
}

- (UILabel *)creatTitleLable
{
    UILabel *l = [[UILabel alloc] init];
    l.textColor = UIColorFromRGB(0x666666, 1);
    l.font = [UIFont systemFontOfSize:14];
    l.numberOfLines = 1;
    
    return l;
}

- (CGFloat)returnTitleWidth:(UILabel *)titleLabel
{
    return titleLabel.intrinsicContentSize.width;
}
@end




















